'''
Created on 26.5.2011

@author: Martin Vegi Kysel
'''
import csv
from csv import Dialect
from PigeonLabTypes.ImageItem import ImageItem


def extractItems(location):
    infile = open(location, 'rU') #'U' means Universal newlines - works equally on Mac, PC Unix.
    extracted_ImageItems = []
    csvObject = csv.reader(infile, Dialect.delimiter==" ")
    
    for row in csvObject:
        if row[0].find("Session")!=-1:
            continue
            #skip the first line
        
        #create new item
        iItem = ImageItem()
        
        #split the row with emptyspace delimeters
        parts = row[0].split()
        
        #fill the image item
        iItem.session = parts[0]
        iItem.trial = parts[1]
        iItem.itemClass = parts[2]
        iItem.image_name = parts[3]
        iItem.numPecks = parts[4]
        
        #add it to the list
        extracted_ImageItems.append(iItem)
    
    return extracted_ImageItems
#=========== eof extractItems ==================


#to run this use
#returnedArray = extractItems("ProcessedLog.log")
#print len(returnedArray)